package cn.com.generaldata.os.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.nutz.dao.Dao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;

import cn.com.generaldata.jsme_indicator_system.entity.BiIndicatorNz;
import cn.com.generaldata.jsme_indicator_system.entity.BiShowNz;
import cn.com.generaldata.jsme_indicator_system.entity.Dustry;
import cn.com.generaldata.jsme_indicator_system.entity.Indicator;
import cn.com.generaldata.jsme_indicator_system.entity.IndicatorRelation;
import cn.com.generaldata.jsme_indicator_system.entity.ReportInputTitle;
import cn.com.generaldata.jsme_indicator_system.entity.ReportTypeIndicator;
import cn.com.generaldata.jsme_indicator_system.entity.ReportTypeLimit;
import cn.com.generaldata.jsme_indicator_system.entity.ReportTypeNz;
import cn.com.generaldata.jsme_indicator_system.entity.ReportTypeUnit;
import cn.com.generaldata.jsme_indicator_system.entity.ReportTypeUnitType;
import cn.com.generaldata.jsme_indicator_system.entity.StatSystem;
import cn.com.generaldata.jsme_indicator_system.entity.UnitRelationNz;
import cn.com.generaldata.os.constant.FilterConstant;
import cn.com.generaldata.os.dao.intf.BaseDAOInterface;
import cn.com.generaldata.os.newpojo.ReportVersion;
import cn.com.generaldata.os.newpojo.SystemCodedic;
import cn.com.generaldata.os.paging.Filter;
import cn.com.generaldata.os.paging.FilterRule;
import cn.com.generaldata.os.pojo.Area;
import cn.com.generaldata.os.pojo.AreaPerform;
import cn.com.generaldata.os.pojo.AuthorFunc;
import cn.com.generaldata.os.pojo.Authority;
import cn.com.generaldata.os.pojo.DustryReport;
import cn.com.generaldata.os.pojo.EnterpriseIndustry;
import cn.com.generaldata.os.pojo.Func;
import cn.com.generaldata.os.pojo.Industry;
import cn.com.generaldata.os.pojo.LArea;
import cn.com.generaldata.os.pojo.Report;
import cn.com.generaldata.os.pojo.ReportDetail;
import cn.com.generaldata.os.pojo.ReportHistory;
import cn.com.generaldata.os.pojo.ReportMarking;
import cn.com.generaldata.os.pojo.ReportStaticContent;
import cn.com.generaldata.os.pojo.ReportUnit;
import cn.com.generaldata.os.pojo.Role;
import cn.com.generaldata.os.pojo.Unit;
import cn.com.generaldata.os.pojo.User;
import cn.com.generaldata.os.pojo.UserIndustry;
import cn.com.generaldata.os.service.intf.ReportEIServiceInterface;

import com.google.common.collect.Lists;

public class ReportEIService implements ReportEIServiceInterface {
	private static Logger log = LoggerFactory.getLogger(ReportEIService.class);
	private BaseDAOInterface<Report> reportDAO;
	private BaseDAOInterface<ReportDetail> reportDetailDAO;
	private BaseDAOInterface<DustryReport> dustryReportDAO;
	private BaseDAOInterface<ReportUnit> reportUnitDAO;
	private BaseDAOInterface<ReportMarking> reportMarkingDAO;
	private BaseDAOInterface<ReportHistory> reportHistoryDAO;
	private BaseDAOInterface<User> userDAO;
	private BaseDAOInterface<Industry> industryDAO;
	private BaseDAOInterface<UserIndustry> userIndustryDAO;
	private BaseDAOInterface<Unit> unitDAO;
	private BaseDAOInterface<AreaPerform> areaPerformDAO;
	private BaseDAOInterface<ReportStaticContent> reportStaticDAO;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportUnit> reportUnitImportDAO;
	private BaseDAOInterface<EnterpriseIndustry> enterpriseIndustryDAO;

	public void setReportUnitImportDAO(BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportUnit> reportUnitImportDAO) {
		this.reportUnitImportDAO = reportUnitImportDAO;
	}

	public void setUnitDAO(BaseDAOInterface<Unit> unitDAO) {
		this.unitDAO = unitDAO;
	}

	private final ExecutorService executorService = Executors.newSingleThreadExecutor();
	private final ExecutorService importService = Executors.newSingleThreadExecutor();
	private BaseDAOInterface<cn.com.generaldata.os.newpojo.ReportType> reportTypeDAO;
	private BaseDAOInterface<cn.com.generaldata.os.newpojo.ReportVersion> reportVersionDAO;
	private BaseDAOInterface<cn.com.generaldata.os.newpojo.SystemCodedic> systemDAO;
	private boolean exportRunning;
	private boolean importRunning;
	@Autowired
	private Dao indicatorSystemDao;
	@Autowired
	private Dao daoExport;
	@Autowired
	private Dao daoImport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.User> userDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.Area> areaDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.LArea> lareaDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.AreaPerform> areaPerformDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.Unit> unitDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.UserIndustry> userIndustryDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.EnterpriseIndustry> enterpriseIndustryDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.DustryReport> dustryReportDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportDetail> reportDetailDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportMarking> reportMarkingDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportHistory> reportHistoryDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.Industry> industryDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportStaticContent> reportStaticDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportStaticContent> reportStaticDAOImport;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.Report> reportDAOImport;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportDetail> reportDetailDAOImport;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportMarking> reportMarkingDAOImport;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportHistory> reportHistoryDAOImport;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.UserIndustry> userIndustryDAOImport;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.User> userDAOImport;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.Unit> unitDAOImport;
	private BaseDAOInterface<cn.com.generaldata.os.importpojo.AreaPerform> areaPerformDAOImport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportType> reportTypeDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportUnit> reportUnitExportDAO;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportVersion> reportVersionDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.SystemCodedic> systemDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportInputTitle> reportTitleDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportTypeIndicator> reportTypeIndicatorDAOExport;
	private BaseDAOInterface<cn.com.generaldata.os.exportpojo.Report> reportDAOExport;

	public void setUnitDAOImport(BaseDAOInterface<cn.com.generaldata.os.importpojo.Unit> unitDAOImport) {
		this.unitDAOImport = unitDAOImport;
	}

	public void setAreaPerformDAO(BaseDAOInterface<AreaPerform> areaPerformDAO) {
		this.areaPerformDAO = areaPerformDAO;
	}

	public void setReportStaticDAO(BaseDAOInterface<ReportStaticContent> reportStaticDAO) {
		this.reportStaticDAO = reportStaticDAO;
	}

	public void setReportStaticDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportStaticContent> reportStaticDAOExport) {
		this.reportStaticDAOExport = reportStaticDAOExport;
	}

	public void setReportStaticDAOImport(
			BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportStaticContent> reportStaticDAOImport) {
		this.reportStaticDAOImport = reportStaticDAOImport;
	}

	public void setAreaPerformDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.AreaPerform> areaPerformDAOExport) {
		this.areaPerformDAOExport = areaPerformDAOExport;
	}

	public void setAreaPerformDAOImport(
			BaseDAOInterface<cn.com.generaldata.os.importpojo.AreaPerform> areaPerformDAOImport) {
		this.areaPerformDAOImport = areaPerformDAOImport;
	}

	public void setReportTypeDAO(BaseDAOInterface<cn.com.generaldata.os.newpojo.ReportType> reportTypeDAO) {
		this.reportTypeDAO = reportTypeDAO;
	}

	public void setReportVersionDAO(BaseDAOInterface<cn.com.generaldata.os.newpojo.ReportVersion> reportVersionDAO) {
		this.reportVersionDAO = reportVersionDAO;
	}

	public void setSystemDAO(BaseDAOInterface<cn.com.generaldata.os.newpojo.SystemCodedic> systemDAO) {
		this.systemDAO = systemDAO;
	}

	public void setReportTypeDAOExport(BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportType> reportTypeDAOExport) {
		this.reportTypeDAOExport = reportTypeDAOExport;
	}

	public void setReportVersionDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportVersion> reportVersionDAOExport) {
		this.reportVersionDAOExport = reportVersionDAOExport;
	}

	public void setSystemDAOExport(BaseDAOInterface<cn.com.generaldata.os.exportpojo.SystemCodedic> systemDAOExport) {
		this.systemDAOExport = systemDAOExport;
	}

	public void setReportTitleDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportInputTitle> reportTitleDAOExport) {
		this.reportTitleDAOExport = reportTitleDAOExport;
	}

	public void setReportTypeIndicatorDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportTypeIndicator> reportTypeIndicatorDAOExport) {
		this.reportTypeIndicatorDAOExport = reportTypeIndicatorDAOExport;
	}

	public void setReportUnitDAO(BaseDAOInterface<ReportUnit> reportUnitDAO) {
		this.reportUnitDAO = reportUnitDAO;
	}

	public void setReportUnitExportDAO(BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportUnit> reportUnitExportDAO) {
		this.reportUnitExportDAO = reportUnitExportDAO;
	}

	public void setReportDAO(BaseDAOInterface<Report> reportDAO) {
		this.reportDAO = reportDAO;
	}

	public void setReportDetailDAO(BaseDAOInterface<ReportDetail> reportDetailDAO) {
		this.reportDetailDAO = reportDetailDAO;
	}

	public void setDustryReportDAO(BaseDAOInterface<DustryReport> dustryReportDAO) {
		this.dustryReportDAO = dustryReportDAO;
	}

	public void setReportMarkingDAO(BaseDAOInterface<ReportMarking> reportMarkingDAO) {
		this.reportMarkingDAO = reportMarkingDAO;
	}

	public void setReportHistoryDAO(BaseDAOInterface<ReportHistory> reportHistoryDAO) {
		this.reportHistoryDAO = reportHistoryDAO;
	}

	public void setUserDAO(BaseDAOInterface<User> userDAO) {
		this.userDAO = userDAO;
	}

	public void setIndustryDAO(BaseDAOInterface<Industry> industryDAO) {
		this.industryDAO = industryDAO;
	}

	public void setUserIndustryDAO(BaseDAOInterface<UserIndustry> userIndustryDAO) {
		this.userIndustryDAO = userIndustryDAO;
	}

	public void setEnterpriseIndustryDAO(BaseDAOInterface<EnterpriseIndustry> enterpriseIndustryDAO) {
		this.enterpriseIndustryDAO = enterpriseIndustryDAO;
	}

	public void setReportDAOExport(BaseDAOInterface<cn.com.generaldata.os.exportpojo.Report> reportDAOExport) {
		this.reportDAOExport = reportDAOExport;
	}

	public void setUserDAOExport(BaseDAOInterface<cn.com.generaldata.os.exportpojo.User> userDAOExport) {
		this.userDAOExport = userDAOExport;
	}

	public void setAreaDAOExport(BaseDAOInterface<cn.com.generaldata.os.exportpojo.Area> areaDAOExport) {
		this.areaDAOExport = areaDAOExport;
	}

	public void setLareaDAOExport(BaseDAOInterface<cn.com.generaldata.os.exportpojo.LArea> lareaDAOExport) {
		this.lareaDAOExport = lareaDAOExport;
	}

	public void setUnitDAOExport(BaseDAOInterface<cn.com.generaldata.os.exportpojo.Unit> unitDAOExport) {
		this.unitDAOExport = unitDAOExport;
	}

	public void setUserIndustryDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.UserIndustry> userIndustryDAOExport) {
		this.userIndustryDAOExport = userIndustryDAOExport;
	}

	public void setEnterpriseIndustryDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.EnterpriseIndustry> enterpriseIndustryDAOExport) {
		this.enterpriseIndustryDAOExport = enterpriseIndustryDAOExport;
	}

	public void setDustryReportDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.DustryReport> dustryReportDAOExport) {
		this.dustryReportDAOExport = dustryReportDAOExport;
	}

	public void setReportDetailDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportDetail> reportDetailDAOExport) {
		this.reportDetailDAOExport = reportDetailDAOExport;
	}

	public void setReportMarkingDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportMarking> reportMarkingDAOExport) {
		this.reportMarkingDAOExport = reportMarkingDAOExport;
	}

	public void setReportHistoryDAOExport(
			BaseDAOInterface<cn.com.generaldata.os.exportpojo.ReportHistory> reportHistoryDAOExport) {
		this.reportHistoryDAOExport = reportHistoryDAOExport;
	}

	public void setIndustryDAOExport(BaseDAOInterface<cn.com.generaldata.os.exportpojo.Industry> industryDAOExport) {
		this.industryDAOExport = industryDAOExport;
	}

	public void setReportDAOImport(BaseDAOInterface<cn.com.generaldata.os.importpojo.Report> reportDAOImport) {
		this.reportDAOImport = reportDAOImport;
	}

	public void setReportDetailDAOImport(
			BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportDetail> reportDetailDAOImport) {
		this.reportDetailDAOImport = reportDetailDAOImport;
	}

	public void setReportMarkingDAOImport(
			BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportMarking> reportMarkingDAOImport) {
		this.reportMarkingDAOImport = reportMarkingDAOImport;
	}

	public void setReportHistoryDAOImport(
			BaseDAOInterface<cn.com.generaldata.os.importpojo.ReportHistory> reportHistoryDAOImport) {
		this.reportHistoryDAOImport = reportHistoryDAOImport;
	}

	public void setUserIndustryDAOImport(
			BaseDAOInterface<cn.com.generaldata.os.importpojo.UserIndustry> userIndustryDAOImport) {
		this.userIndustryDAOImport = userIndustryDAOImport;
	}

	public void setUserDAOImport(BaseDAOInterface<cn.com.generaldata.os.importpojo.User> userDAOImport) {
		this.userDAOImport = userDAOImport;
	}

	// //导出所有报表模板
	@Override
	public Boolean exportReportType() {
		if (!exportRunning) {
			executorService.execute(new ExportTypeTask());
		}
		return true;
	}

	class ExportTypeTask implements Runnable {
		@Override
		public void run() {
			exportRunning = true;
			// SystemCodedic同步
			try {
				List<SystemCodedic> systemList = systemDAO.find(SystemCodedic.class, null, null);
				List<cn.com.generaldata.os.exportpojo.SystemCodedic> find = systemDAOExport.find(
						cn.com.generaldata.os.exportpojo.SystemCodedic.class, null, null);
				systemDAOExport.delete(find);
				for (SystemCodedic sc : systemList) {
					cn.com.generaldata.os.exportpojo.SystemCodedic sysCode = new cn.com.generaldata.os.exportpojo.SystemCodedic();
					BeanUtils.copyProperties(sc, sysCode);
					systemDAOExport.save(sysCode);
				}
				// ReportInputTitle同步
				List<ReportInputTitle> queryList = indicatorSystemDao.query(ReportInputTitle.class, null);
				daoExport.clear(ReportInputTitle.class);
				daoExport.insert(queryList);

				// ReportTypeLimit同步
				List<ReportTypeLimit> limitList = indicatorSystemDao.query(ReportTypeLimit.class, null);
				daoExport.clear(ReportTypeLimit.class);
				daoExport.insert(limitList);

				//BiIndicator同步
				List<BiIndicatorNz> biList = indicatorSystemDao.query(BiIndicatorNz.class, null);
				daoExport.clear(BiIndicatorNz.class);
				daoExport.insert(biList);

				//BiShow同步
				List<BiShowNz> biShowList = indicatorSystemDao.query(BiShowNz.class, null);
				daoExport.clear(BiShowNz.class);
				daoExport.insert(biShowList);

				// StatSystem同步
				List<StatSystem> statList = indicatorSystemDao.query(StatSystem.class, null);
				daoExport.clear(StatSystem.class);
				daoExport.insert(statList);
				// UnitRelationNz同步
				List<UnitRelationNz> unitRelation = indicatorSystemDao.query(UnitRelationNz.class, null);
				daoExport.clear(UnitRelationNz.class);
				daoExport.insert(unitRelation);
				// DustryReport同步
				List<DustryReport> dustryReportList = dustryReportDAO.find(DustryReport.class, null, null);
				List<cn.com.generaldata.os.exportpojo.DustryReport> find2 = dustryReportDAOExport.find(
						cn.com.generaldata.os.exportpojo.DustryReport.class, null, null);
				dustryReportDAOExport.delete(find2);
				for (DustryReport rt : dustryReportList) {
					cn.com.generaldata.os.exportpojo.DustryReport rtExport = new cn.com.generaldata.os.exportpojo.DustryReport();
					BeanUtils.copyProperties(rt, rtExport);
					if (rt.getIndustry() != null)
						rtExport.setIndustry1(rt.getIndustry().getId());
					dustryReportDAOExport.save(rtExport);
				}
				// ReportType同步
				List<ReportTypeNz> reportTypeList = indicatorSystemDao.query(ReportTypeNz.class, null, null);
				if (reportTypeList != null && reportTypeList.size() > 0) {
					daoExport.clear(ReportTypeNz.class);
					daoExport.insert(reportTypeList);
				}

				// ReportVersion同步
				List<ReportVersion> reportVersionList = reportVersionDAO.find(ReportVersion.class, null, null);
				List<cn.com.generaldata.os.exportpojo.ReportVersion> find4 = reportVersionDAOExport.find(
						cn.com.generaldata.os.exportpojo.ReportVersion.class, null, null);
				reportVersionDAOExport.delete(find4);
				for (ReportVersion rv : reportVersionList) {
					cn.com.generaldata.os.exportpojo.ReportVersion rtExport = new cn.com.generaldata.os.exportpojo.ReportVersion();
					BeanUtils.copyProperties(rv, rtExport);
					reportVersionDAOExport.save(rtExport);
				}

				// Indicator同步
				List<Indicator> indicator = indicatorSystemDao.query(Indicator.class, null);
				daoExport.clear(Indicator.class);
				daoExport.insert(indicator);

				// IndicatorRelation同步
				List<IndicatorRelation> indicatorRelation = indicatorSystemDao.query(IndicatorRelation.class, null);
				daoExport.clear(IndicatorRelation.class);
				daoExport.insert(indicatorRelation);

				// ReportTypeIndicator同步
				List<ReportTypeIndicator> indicatorList = indicatorSystemDao.query(ReportTypeIndicator.class, null);
				daoExport.clear(ReportTypeIndicator.class);
				daoExport.insert(indicatorList);

				// ReportTypeUnitType同步
				List<ReportTypeUnitType> tutList = indicatorSystemDao.query(ReportTypeUnitType.class, null);
				daoExport.clear(ReportTypeUnitType.class);
				daoExport.insert(tutList);

				// AreaPerform同步
				List<AreaPerform> apList = areaPerformDAO.find(AreaPerform.class, null, null);
				List<cn.com.generaldata.os.exportpojo.AreaPerform> find5 = areaPerformDAOExport.find(
						cn.com.generaldata.os.exportpojo.AreaPerform.class, null, null);
				areaPerformDAOExport.delete(find5);
				for (AreaPerform ap : apList) {
					cn.com.generaldata.os.exportpojo.AreaPerform areaPerformE = new cn.com.generaldata.os.exportpojo.AreaPerform();
					BeanUtils.copyProperties(ap, areaPerformE);
					areaPerformDAOExport.save(areaPerformE);

				}

				// tbl_dustry同步
				List<Dustry> dusList = indicatorSystemDao.query(Dustry.class, null);
				daoExport.clear(Dustry.class);
				daoExport.insert(dusList);

				// tbl_authority同步
				List<Authority> authorityList = indicatorSystemDao.query(Authority.class, null);
				daoExport.clear(Authority.class);
				daoExport.insert(authorityList);

				// tbl_author_func同步
				List<AuthorFunc> authorFuncList = indicatorSystemDao.query(AuthorFunc.class, null);
				daoExport.clear(AuthorFunc.class);
				daoExport.insert(authorFuncList);

				// tbl_func同步
				List<Func> funcList = indicatorSystemDao.query(Func.class, null);
				daoExport.clear(Func.class);
				daoExport.insert(funcList);

				// Report_static_content同步
				List<ReportStaticContent> rsList = reportStaticDAO.find(ReportStaticContent.class, null, null);
				List<cn.com.generaldata.os.exportpojo.ReportStaticContent> find6 = reportStaticDAOExport.find(
						cn.com.generaldata.os.exportpojo.ReportStaticContent.class, null, null);
				reportStaticDAOExport.delete(find6);
				for (ReportStaticContent rs : rsList) {
					cn.com.generaldata.os.exportpojo.ReportStaticContent rsE = new cn.com.generaldata.os.exportpojo.ReportStaticContent();
					BeanUtils.copyProperties(rs, rsE);
					reportStaticDAOExport.save(rsE);
				}

				// ReportTypeUnit同步
				List<ReportTypeUnit> rtuList = indicatorSystemDao.query(ReportTypeUnit.class, null);
				daoExport.clear(ReportTypeUnit.class);
				daoExport.insert(rtuList);
			} catch (BeansException e) {
				// TODO Auto-generated catch block
				exportRunning = false;
				e.printStackTrace();
			}

			exportRunning = false;
			System.out.print("clear!");
		}
	}

	// 首先查看ReportStaticID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isReportStaticIdExist(Integer rsId) {
		cn.com.generaldata.os.exportpojo.ReportStaticContent rs = reportStaticDAOExport.get(
				cn.com.generaldata.os.exportpojo.ReportStaticContent.class, rsId);
		if (rs != null) {
			return true;
		}
		return false;
	}

	// 首先查看areaPerformID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isAreaPerformIdExist(String apId) {
		cn.com.generaldata.os.exportpojo.AreaPerform ap = areaPerformDAOExport.get(
				cn.com.generaldata.os.exportpojo.AreaPerform.class, apId);
		if (ap != null) {
			return true;
		}
		return false;
	}

	class ExportTask implements Runnable {
		private final Set<String> rids;

		public ExportTask(Set<String> rids) {
			this.rids = rids;
		}

		@Override
		public void run() {
			exportRunning = true;
			List<List<String>> parReports = Lists.partition(Lists.newArrayList(rids), 10);
			for (List<String> parReport : parReports) {

				try {
					exportReport(parReport);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					continue;
				}
			}
			exportRunning = false;
			System.out.print("clear!");
		}

		private void exportReport(List<String> parReport) {
			Filter reportFilter = new Filter();
			reportFilter.addRule(new FilterRule(FilterConstant.COLLECTION, "id", parReport.toArray()));
			//				reportFilter.addRule(new FilterRule(FilterConstant.OR,
			//						"reportReferenceId", ""));
			// 需导出的报表
			List<Report> reportList = reportDAO.find(Report.class, reportFilter, null);
			if (reportList != null && reportList.size() > 0) {

				for (Report report : reportList) {
					// 导出报表
					cn.com.generaldata.os.exportpojo.Report reportE = reportDAOExport.get(
							cn.com.generaldata.os.exportpojo.Report.class, report.getId());
					if (reportE != null) {
						reportDAOExport.delete(reportE);
					}
					reportE = new cn.com.generaldata.os.exportpojo.Report();
					BeanUtils.copyProperties(report, reportE);
					if (report.getArea() != null) {
						reportE.setArea1(report.getArea().getId());
					}
					if (report.getOperator() != null) {
						reportE.setOperator1(report.getOperator().getId());
					}
					if (report.getUser() != null) {
						reportE.setUser1(report.getUser().getId());
					}
					reportDAOExport.save(reportE);

					report.setReportFlag("1");
					reportDAO.update(report);
					//导出报表审批记录
					Filter unitFilter = new Filter();
					unitFilter.addRule(new FilterRule(FilterConstant.EQUAL, "reportId", report.getId()));
					List<ReportUnit> ruList = reportUnitDAO.find(ReportUnit.class, unitFilter, null);
					List<cn.com.generaldata.os.exportpojo.ReportUnit> find = reportUnitExportDAO.find(
							cn.com.generaldata.os.exportpojo.ReportUnit.class, unitFilter, null);
					if (ruList != null && ruList.size() > 0) {
						reportUnitExportDAO.delete(find);
						for (ReportUnit ru : ruList) {
							// 导出报表审批记录
							cn.com.generaldata.os.exportpojo.ReportUnit ruE = new cn.com.generaldata.os.exportpojo.ReportUnit();
							BeanUtils.copyProperties(ru, ruE);
							reportUnitExportDAO.save(ruE);
						}
					}
					Filter detailFilter = new Filter();
					detailFilter.addRule(new FilterRule(FilterConstant.EQUAL, "report.id", report.getId()));
					List<ReportDetail> rdList = reportDetailDAO.find(ReportDetail.class, detailFilter, null);
					Filter detailExportFilter = new Filter();
					detailExportFilter.addRule(new FilterRule(FilterConstant.EQUAL, "report1", report.getId()));
					List<cn.com.generaldata.os.exportpojo.ReportDetail> find2 = reportDetailDAOExport.find(
							cn.com.generaldata.os.exportpojo.ReportDetail.class, detailExportFilter, null);
					if (rdList != null && rdList.size() > 0) {
						reportDetailDAOExport.delete(find2);
						for (ReportDetail rd : rdList) {

							// 导出报表详细
							cn.com.generaldata.os.exportpojo.ReportDetail rdE = new cn.com.generaldata.os.exportpojo.ReportDetail();
							BeanUtils.copyProperties(rd, rdE);
							if (rd.getReport() != null) {
								rdE.setReport1(rd.getReport().getId());
							}
							reportDetailDAOExport.save(rdE);
						}
					}
					List<ReportHistory> rhList = reportHistoryDAO.find(ReportHistory.class, detailFilter, null);
					List<cn.com.generaldata.os.exportpojo.ReportHistory> find3 = reportHistoryDAOExport.find(
							cn.com.generaldata.os.exportpojo.ReportHistory.class, detailExportFilter, null);
					if (rhList != null && rhList.size() > 0) {
						reportHistoryDAOExport.delete(find3);
						for (ReportHistory rh : rhList) {

							// 导出报表历史
							cn.com.generaldata.os.exportpojo.ReportHistory rhE = new cn.com.generaldata.os.exportpojo.ReportHistory();
							BeanUtils.copyProperties(rh, rhE);
							if (rh.getOperator() != null) {
								rhE.setOperator1(rh.getOperator().getId());
							}
							if (rh.getReport() != null) {
								rhE.setReport1(rh.getReport().getId());
							}
							reportHistoryDAOExport.save(rhE);
						}
					}
					List<ReportMarking> rmList = reportMarkingDAO.find(ReportMarking.class, detailFilter, null);
					List<cn.com.generaldata.os.exportpojo.ReportMarking> find4 = reportMarkingDAOExport.find(
							cn.com.generaldata.os.exportpojo.ReportMarking.class, detailExportFilter, null);
					if (rmList != null && rmList.size() > 0) {
						reportMarkingDAOExport.delete(find4);
						for (ReportMarking rm : rmList) {
							// 导出报表标签
							cn.com.generaldata.os.exportpojo.ReportMarking rmE = new cn.com.generaldata.os.exportpojo.ReportMarking();
							BeanUtils.copyProperties(rm, rmE);
							if (rm.getOperator() != null) {
								rmE.setOperator1(rm.getOperator().getId());
							}
							if (rm.getReport() != null) {
								rmE.setReport1(rm.getReport().getId());
							}
							reportMarkingDAOExport.save(rmE);

						}
					}
				}
			}
		}

	}

	// 将业务库的终审通过或驳回报表导到导出库
	@Override
	public Boolean exportEIReport(Set<String> rids) {
		if (!exportRunning) {
			executorService.execute(new ExportTask(rids));
		}
		return true;
	}

	// 将业务库的已更新用户导入到导出库user_flag=0
	@Override
	public boolean exportUser(String[] ids) {
		for (String uid : ids) {
			if (!isUserIdExist(uid)) {
				User user = userDAO.get(User.class, uid);
				Unit userUnit = user.getUserUnit();
				Area area = userUnit.getArea();
				LArea larea = userUnit.getLarea();
				// 导出区域
				if (area != null && !isAreaIdExist(area.getId())) {
					cn.com.generaldata.os.exportpojo.Area areaE = new cn.com.generaldata.os.exportpojo.Area();
					BeanUtils.copyProperties(area, areaE);
					areaDAOExport.saveOrUpdate(areaE);
				}
				// 导出村级区域
				if (larea != null && !isLAreaIdExist(larea.getId())) {
					cn.com.generaldata.os.exportpojo.LArea lareaE = new cn.com.generaldata.os.exportpojo.LArea();
					BeanUtils.copyProperties(larea, lareaE);
					lareaDAOExport.saveOrUpdate(lareaE);
				}
				// 导出单位
				if (userUnit != null && !isUnitIdExist(userUnit.getId())) {
					cn.com.generaldata.os.exportpojo.Unit unitE = new cn.com.generaldata.os.exportpojo.Unit();
					BeanUtils.copyProperties(userUnit, unitE);
					if (userUnit.getArea() != null) {
						unitE.setArea1(userUnit.getArea().getId());
					}
					if (userUnit.getLarea() != null) {
						unitE.setLarea1(userUnit.getLarea().getId());
					}
					if (userUnit.getRegistArea() != null) {
						unitE.setRegistArea1(userUnit.getRegistArea().getId());
					}
					if (userUnit.getRegistLArea() != null) {
						unitE.setRegistLArea1(userUnit.getRegistLArea().getId());
					}
					if (userUnit.getRole() != null) {
						unitE.setRole1(userUnit.getRole().getId());
					}
					unitDAOExport.saveOrUpdate(unitE);
				}
				// 导出用户
				cn.com.generaldata.os.exportpojo.User userE = new cn.com.generaldata.os.exportpojo.User();
				BeanUtils.copyProperties(user, userE);
				if (user.getArea() != null) {
					userE.setArea1(user.getArea().getId());
				}
				if (user.getRole() != null) {
					userE.setRole1(user.getRole().getId());
				}
				if (user.getUserUnit() != null) {
					userE.setUserUnit1(user.getUserUnit().getId());
				}
				userDAOExport.saveOrUpdate(userE);
				// 导出用户对应的企业行业分组和报表制度行业分组
				Filter userIndustryFilter = new Filter();
				userIndustryFilter.addRule(new FilterRule(FilterConstant.EQUAL, "user.id", uid));
				List<UserIndustry> uilist = userIndustryDAO.find(UserIndustry.class, userIndustryFilter, null);
				if (uilist != null && uilist.size() > 0) {
					for (UserIndustry ui : uilist) {
						Industry industry = ui.getIndustry();
						if (!isIndustryExist(industry.getId())) {
							// 导出行业
							cn.com.generaldata.os.exportpojo.Industry inE = new cn.com.generaldata.os.exportpojo.Industry();
							BeanUtils.copyProperties(industry, inE);
							industryDAOExport.saveOrUpdate(inE);
						}
						if (!isUserIndustryExist(ui.getId())) {
							// 导出报表制度行业分组
							cn.com.generaldata.os.exportpojo.UserIndustry uiE = new cn.com.generaldata.os.exportpojo.UserIndustry();
							BeanUtils.copyProperties(ui, uiE);
							if (ui.getIndustry() != null) {
								uiE.setIndustry1(ui.getIndustry().getId());
							}
							if (ui.getUser() != null) {
								uiE.setUser1(ui.getUser().getId());
							}
							userIndustryDAOExport.saveOrUpdate(uiE);

						}
					}
				}
			}
		}
		exportOverUser(ids);
		System.out.print("clear!");
		return true;
	}

	// 更改用户导出完成状态
	@Override
	public boolean exportOverUser(String[] ids) {
		for (String uid : ids) {
			User user = userDAO.get(User.class, uid);
			user.setUserFlag("1");
			userDAO.update(user);
		}
		return true;
	}

	@Override
	// 首先查看报表ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isReportIdExist(String reportId) {
		cn.com.generaldata.os.exportpojo.Report report = reportDAOExport.get(
				cn.com.generaldata.os.exportpojo.Report.class, reportId);
		if (report != null) {
			return true;
		}
		return false;
	}

	// 首先查看报表详细ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isReportDetailIdExist(String rdId) {
		cn.com.generaldata.os.exportpojo.ReportDetail report = reportDetailDAOExport.get(
				cn.com.generaldata.os.exportpojo.ReportDetail.class, rdId);
		if (report != null) {
			return true;
		}
		return false;
	}

	// 首先查看报表历史ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isReportHistoryIdExist(String rdId) {
		cn.com.generaldata.os.exportpojo.ReportHistory report = reportHistoryDAOExport.get(
				cn.com.generaldata.os.exportpojo.ReportHistory.class, rdId);
		if (report != null) {
			return true;
		}
		return false;
	}

	// 首先查看报表标记ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isReportMarkIdExist(String rdId) {
		cn.com.generaldata.os.exportpojo.ReportMarking report = reportMarkingDAOExport.get(
				cn.com.generaldata.os.exportpojo.ReportMarking.class, rdId);
		if (report != null) {
			return true;
		}
		return false;
	}

	// 首先查看用户ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isUserIdExist(String userId) {
		cn.com.generaldata.os.exportpojo.User user = userDAOExport.get(cn.com.generaldata.os.exportpojo.User.class,
				userId);
		if (user != null) {
			return true;
		}
		return false;
	}

	// 查看区域ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isAreaIdExist(String areaId) {
		cn.com.generaldata.os.exportpojo.Area area = areaDAOExport.get(cn.com.generaldata.os.exportpojo.Area.class,
				areaId);
		if (area != null) {
			return true;
		}
		return false;
	}

	// 查看村级区域ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isLAreaIdExist(String lareaId) {
		cn.com.generaldata.os.exportpojo.LArea larea = lareaDAOExport.get(cn.com.generaldata.os.exportpojo.LArea.class,
				lareaId);
		if (larea != null) {
			return true;
		}
		return false;
	}

	// 查看单位ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isUnitIdExist(String unitId) {
		cn.com.generaldata.os.exportpojo.Unit unit = unitDAOExport.get(cn.com.generaldata.os.exportpojo.Unit.class,
				unitId);
		if (unit != null) {
			return true;
		}
		return false;
	}

	// 首先查看用户ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isUserIndustryExist(String uiId) {
		cn.com.generaldata.os.exportpojo.UserIndustry ui = userIndustryDAOExport.get(
				cn.com.generaldata.os.exportpojo.UserIndustry.class, uiId);
		if (ui != null) {
			return true;
		}
		return false;
	}

	// 首先查看行业ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isIndustryExist(String industryId) {
		cn.com.generaldata.os.exportpojo.Industry ui = industryDAOExport.get(
				cn.com.generaldata.os.exportpojo.Industry.class, industryId);
		if (ui != null) {
			return true;
		}
		return false;
	}

	// 首先查看用户ID是已经在导出库中存在，没有则添加，否则跳过
	public boolean isEnterpriseIndustryExist(String eiId) {
		cn.com.generaldata.os.exportpojo.EnterpriseIndustry ei = enterpriseIndustryDAOExport.get(
				cn.com.generaldata.os.exportpojo.EnterpriseIndustry.class, eiId);
		if (ei != null) {
			return true;
		}
		return false;
	}

	// 首先查看报表ID是已经在存在，没有则添加，否则跳过
	public Report existReport(String reportId) {
		Report report = reportDAO.get(Report.class, reportId);
		if (report != null) {
			return report;
		}
		return null;
	}

	// 首先查看报表详细ID是已经存在，没有则添加，否则跳过
	public ReportDetail existReportDetail(String rdId) {
		ReportDetail report = reportDetailDAO.get(ReportDetail.class, rdId);
		if (report != null) {
			return report;
		}
		return null;
	}

	// 首先查看报表历史ID是已经存在，没有则添加，否则跳过
	public ReportHistory existReportHistory(String rdId) {
		ReportHistory report = reportHistoryDAO.get(ReportHistory.class, rdId);
		if (report != null) {
			return report;
		}
		return null;
	}

	// 首先查看报表标记ID是已经存在，没有则添加，否则跳过
	public ReportMarking existReportMarking(String rdId) {
		ReportMarking report = reportMarkingDAO.get(ReportMarking.class, rdId);
		if (report != null) {
			return report;
		}
		return null;
	}

	class ImportTask implements Runnable {
		List<cn.com.generaldata.os.vo.ReportVO> reports = new ArrayList<cn.com.generaldata.os.vo.ReportVO>();

		@Override
		public void run() {
			importRunning = true;
			// 需要导入报表
			try {
				List<cn.com.generaldata.os.importpojo.Report> imReports = reportDAOImport.find(
						cn.com.generaldata.os.importpojo.Report.class, null, null);
				if (imReports != null && imReports.size() > 0) {
					for (cn.com.generaldata.os.importpojo.Report im : imReports) {
						Report report = existReport(im.getId());
						if (report != null) {
							BeanUtils.copyProperties(im, report);
							Area area = new Area();
							area.setId(im.getArea1());
							report.setArea(area);
							User operator = new User();
							operator.setId(im.getOperator1());
							report.setOperator(operator);
							User user = new User();
							user.setId(im.getUser1());
							report.setUser(user);
							report.setReportFlag("1");
							reportDAO.update(report);
						} else {
							report = new Report();
							BeanUtils.copyProperties(im, report);
							Area area = new Area();
							area.setId(im.getArea1());
							report.setArea(area);
							User operator = new User();
							operator.setId(im.getOperator1());
							report.setOperator(operator);
							User user = new User();
							user.setId(im.getUser1());
							report.setUser(user);
							report.setReportFlag("1");
							reportDAO.save(report);
						}
						Filter unitFilter = new Filter();
						unitFilter.addRule(new FilterRule(FilterConstant.EQUAL, "reportId", im.getId()));
						List<ReportUnit> ruList = reportUnitDAO.find(ReportUnit.class, unitFilter, null);
						List<cn.com.generaldata.os.importpojo.ReportUnit> find = reportUnitImportDAO.find(
								cn.com.generaldata.os.importpojo.ReportUnit.class, unitFilter, null);
						if (find != null && find.size() > 0) {
							reportUnitDAO.delete(ruList);
							for (cn.com.generaldata.os.importpojo.ReportUnit ru : find) {
								// 导出报表审批记录
								ReportUnit ruE = new ReportUnit();
								BeanUtils.copyProperties(ru, ruE);
								reportUnitDAO.save(ruE);
							}
						}
						Filter detailFilter = new Filter();
						detailFilter.addRule(new FilterRule(FilterConstant.EQUAL, "report1", im.getId()));
						List<cn.com.generaldata.os.importpojo.ReportDetail> imReportDetails = reportDetailDAOImport
								.find(cn.com.generaldata.os.importpojo.ReportDetail.class, detailFilter, null);
						Filter detailWebFilter = new Filter();
						detailWebFilter.addRule(new FilterRule(FilterConstant.EQUAL, "report.id", im.getId()));
						List<ReportDetail> find2 = reportDetailDAO.find(ReportDetail.class, detailWebFilter, null);
						if (imReportDetails != null && imReportDetails.size() > 0) {
							reportDetailDAO.delete(find2);
							for (cn.com.generaldata.os.importpojo.ReportDetail imDetail : imReportDetails) {
								ReportDetail reportDetail = new ReportDetail();
								BeanUtils.copyProperties(imDetail, reportDetail);
								Report report2 = new Report();
								report2.setId(imDetail.getReport1());
								reportDetail.setReport(report2);
								reportDetailDAO.save(reportDetail);
							}
						}
						List<cn.com.generaldata.os.importpojo.ReportHistory> imReportHistorys = reportHistoryDAOImport
								.find(cn.com.generaldata.os.importpojo.ReportHistory.class, detailFilter, null);
						List<ReportHistory> find3 = reportHistoryDAO.find(ReportHistory.class, detailWebFilter, null);

						if (imReportHistorys != null && imReportHistorys.size() > 0) {
							reportHistoryDAO.delete(find3);
							for (cn.com.generaldata.os.importpojo.ReportHistory imHistory : imReportHistorys) {
								ReportHistory reportHistory = new ReportHistory();
								BeanUtils.copyProperties(imHistory, reportHistory);
								Report report2 = new Report();
								report2.setId(imHistory.getReport1());
								reportHistory.setReport(report2);
								User operator = new User();
								operator.setId(imHistory.getOperator1());
								reportHistory.setOperator(operator);
								reportHistoryDAO.save(reportHistory);
							}
						}

						List<cn.com.generaldata.os.importpojo.ReportMarking> imReportMarkings = reportMarkingDAOImport
								.find(cn.com.generaldata.os.importpojo.ReportMarking.class, detailFilter, null);

						List<ReportMarking> find4 = reportMarkingDAO.find(ReportMarking.class, detailWebFilter, null);

						if (imReportMarkings != null && imReportMarkings.size() > 0) {
							reportMarkingDAO.delete(find4);
							for (cn.com.generaldata.os.importpojo.ReportMarking imMarking : imReportMarkings) {
								ReportMarking reportMarking = new ReportMarking();
								BeanUtils.copyProperties(imMarking, reportMarking);
								Report report2 = new Report();
								report2.setId(imMarking.getReport1());
								reportMarking.setReport(report2);
								User operator = new User();
								operator.setId(imMarking.getOperator1());
								reportMarking.setOperator(operator);
								reportMarkingDAO.save(reportMarking);
							}

						}
						cn.com.generaldata.os.vo.ReportVO reportVO = new cn.com.generaldata.os.vo.ReportVO();
						BeanUtils.copyProperties(report, reportVO);
						if (report.getArea() != null) {
							reportVO.setAreaId(report.getArea().getId());
						}
						if (report.getOperator() != null) {
							reportVO.setOperatorId(report.getOperator().getId());
							reportVO.setOperatorName(report.getOperator().getUserLoginname());
						}
						if (report.getUser() != null) {
							reportVO.setUserId(report.getUser().getId());
						}
						reports.add(reportVO);
					}
				}
				importUser();
			} catch (BeansException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				importRunning = false;
			}

			if (reports.size() > 0) { // 存在导入数据，导入后清空导入库数据
				cleanImReport(); // 清空导入库数据
			}
			importRunning = false;
		}
	}

	// 查看单位ID是已经在导出库中存在，没有则添加，否则跳过
	public Unit isUnitIdImport(String unitId) {
		Unit unit = unitDAO.get(Unit.class, unitId);
		if (unit != null) {
			return unit;
		}
		return null;
	}

	public boolean importUser() {

		List<cn.com.generaldata.os.importpojo.User> list = userDAOImport.find(
				cn.com.generaldata.os.importpojo.User.class, null, null);
		for (cn.com.generaldata.os.importpojo.User user : list) {
			String unitId = user.getUserUnit1();

			//			Filter unitFilter = new Filter();
			//			unitFilter.addRule(new FilterRule(FilterConstant.EQUAL, "id", unitId));
			cn.com.generaldata.os.importpojo.Unit unitl = unitDAOImport.get(
					cn.com.generaldata.os.importpojo.Unit.class, unitId);
			// 导出单位
			if (unitl != null) {
				//				cn.com.generaldata.os.importpojo.Unit unit = unitList.get(0);
				Unit unitE = isUnitIdImport(unitId);
				if (unitE == null)
					unitE = new Unit();
				BeanUtils.copyProperties(unitl, unitE);
				if (unitl.getArea1() != null) {
					Area area = new Area();
					area.setId(unitl.getArea1());
					unitE.setArea(area);
				}
				if (unitl.getLarea1() != null) {
					LArea area = new LArea();
					area.setId(unitl.getLarea1());
					unitE.setLarea(area);
				}
				if (unitl.getRegistArea1() != null) {
					Area area = new Area();
					area.setId(unitl.getRegistArea1());
					unitE.setRegistArea(area);
				}
				if (unitl.getRegistLArea1() != null) {
					LArea area = new LArea();
					area.setId(unitl.getLarea1());
					unitE.setRegistLArea(area);
				}
				if (unitl.getRole1() != null) {
					Role area = new Role();
					area.setId(unitl.getRole1());
					unitE.setRole(area);
				}
				unitDAO.saveOrUpdate(unitE);
			}

			User userE = isUserIdImport(user.getId());
			String userPasswd = "";
			if (userE == null)
				// 导出用户
				userE = new User();
			else
				userPasswd = userE.getUserPasswd();
			BeanUtils.copyProperties(user, userE);
			if (user.getArea1() != null) {
				Area area = new Area();
				area.setId(user.getArea1());
				userE.setArea(area);
			}
			if (user.getRole1() != null) {
				Role area = new Role();
				area.setId(user.getRole1());
				userE.setRole(area);
			}
			if (user.getUserUnit1() != null) {
				Unit area = new Unit();
				area.setId(user.getUserUnit1());
				userE.setUserUnit(area);
			}
			if (!"".equals(userPasswd))
				userE.setUserPasswd(userPasswd);
			userE.setUserFlag("1");
			userDAO.saveOrUpdate(userE);
		}

		System.out.print("user clear!");
		return true;
	}

	// 首先查看用户ID是已经在导出库中存在，没有则添加，否则跳过
	public User isUserIdImport(String userId) {
		User user = userDAO.get(User.class, userId);
		if (user != null) {
			return user;
		}
		return null;
	}

	// 将导出入库导入到业务库的已上报报表
	@Override
	public List<cn.com.generaldata.os.vo.ReportVO> importEIReport() {
		ImportTask importTask = new ImportTask();
		if (!importRunning) {
			importService.execute(importTask);
		}
		return importTask.reports;
	}

	// 自动清除导出库的数据
	@Override
	public Boolean cleanEIReport() {
		List<cn.com.generaldata.os.exportpojo.ReportMarking> rmlist = reportMarkingDAOExport.find(
				cn.com.generaldata.os.exportpojo.ReportMarking.class, null, null);
		reportMarkingDAOExport.delete(rmlist);
		List<cn.com.generaldata.os.exportpojo.ReportHistory> rhlist = reportHistoryDAOExport.find(
				cn.com.generaldata.os.exportpojo.ReportHistory.class, null, null);
		reportHistoryDAOExport.delete(rhlist);
		List<cn.com.generaldata.os.exportpojo.ReportDetail> rdlist = reportDetailDAOExport.find(
				cn.com.generaldata.os.exportpojo.ReportDetail.class, null, null);
		reportDetailDAOExport.delete(rdlist);
		List<cn.com.generaldata.os.exportpojo.Report> rlist = reportDAOExport.find(
				cn.com.generaldata.os.exportpojo.Report.class, null, null);
		reportDAOExport.delete(rlist);

		List<cn.com.generaldata.os.exportpojo.EnterpriseIndustry> eilist = enterpriseIndustryDAOExport.find(
				cn.com.generaldata.os.exportpojo.EnterpriseIndustry.class, null, null);
		enterpriseIndustryDAOExport.delete(eilist);
		List<cn.com.generaldata.os.exportpojo.UserIndustry> uilist = userIndustryDAOExport.find(
				cn.com.generaldata.os.exportpojo.UserIndustry.class, null, null);
		userIndustryDAOExport.delete(uilist);

		List<cn.com.generaldata.os.exportpojo.User> userlist = userDAOExport.find(
				cn.com.generaldata.os.exportpojo.User.class, null, null);
		userDAOExport.delete(userlist);
		List<cn.com.generaldata.os.exportpojo.Unit> unitlist = unitDAOExport.find(
				cn.com.generaldata.os.exportpojo.Unit.class, null, null);
		unitDAOExport.delete(unitlist);

		List<cn.com.generaldata.os.exportpojo.DustryReport> drlist = dustryReportDAOExport.find(
				cn.com.generaldata.os.exportpojo.DustryReport.class, null, null);
		dustryReportDAOExport.delete(drlist);
		List<cn.com.generaldata.os.exportpojo.Industry> inlist = industryDAOExport.find(
				cn.com.generaldata.os.exportpojo.Industry.class, null, null);
		industryDAOExport.delete(inlist);

		// 由于行业是基本信息，清楚后就更新成最新，保持内外网一致
		// 导入行业主表
		List<Industry> list = industryDAO.find(Industry.class, null, null);
		if (list != null && list.size() > 0) {
			for (Industry industry : list) {

				// 导出行业
				cn.com.generaldata.os.exportpojo.Industry inE = new cn.com.generaldata.os.exportpojo.Industry();
				BeanUtils.copyProperties(industry, inE);
				industryDAOExport.saveOrUpdate(inE);
			}
		}
		// 导入行业与报表的关系表
		List<DustryReport> drlists = dustryReportDAO.find(DustryReport.class, null, null);
		if (drlists != null && drlists.size() > 0) {
			for (DustryReport dr : drlists) {

				// 导入行业与报表的关系表
				cn.com.generaldata.os.exportpojo.DustryReport drE = new cn.com.generaldata.os.exportpojo.DustryReport();
				BeanUtils.copyProperties(dr, drE);
				if (dr.getIndustry() != null) {
					drE.setIndustry1(dr.getIndustry().getId());
				}
				dustryReportDAOExport.saveOrUpdate(drE);
			}
		}
		return true;

	}

	// 自动清除导入库的数据
	public void cleanImReport() {
		List<cn.com.generaldata.os.importpojo.ReportMarking> rmlist = reportMarkingDAOImport.find(
				cn.com.generaldata.os.importpojo.ReportMarking.class, null, null);
		reportMarkingDAOImport.delete(rmlist);

		List<cn.com.generaldata.os.importpojo.ReportHistory> rhlist = reportHistoryDAOImport.find(
				cn.com.generaldata.os.importpojo.ReportHistory.class, null, null);
		reportHistoryDAOImport.delete(rhlist);
		List<cn.com.generaldata.os.importpojo.ReportDetail> rdlist = reportDetailDAOImport.find(
				cn.com.generaldata.os.importpojo.ReportDetail.class, null, null);
		reportDetailDAOImport.delete(rdlist);
		List<cn.com.generaldata.os.importpojo.Report> rlist = reportDAOImport.find(
				cn.com.generaldata.os.importpojo.Report.class, null, null);
		reportDAOImport.delete(rlist);
		List<cn.com.generaldata.os.importpojo.UserIndustry> uilist = userIndustryDAOImport.find(
				cn.com.generaldata.os.importpojo.UserIndustry.class, null, null);
		userIndustryDAOImport.delete(uilist);
		List<cn.com.generaldata.os.importpojo.User> ulist = userDAOImport.find(
				cn.com.generaldata.os.importpojo.User.class, null, null);
		userDAOImport.delete(ulist);
	}

	/* 判断字符串是否为空,当判断的为从数据库中提取的字段时，得加上判断null */
	public static Boolean NotisNULL(String para) {
		if (para != null && !para.trim().equals("") && !para.trim().equals("null")) {
			return true;
		} else {
			return false;
		}
	}
}
